﻿using System.Collections.Generic;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using Contracts.Entities;

namespace Model.MovieElements
{
    class GenreConverter
    {
        /// <summary>
        /// Für das Lesen einer GenreActors-Relation
        /// </summary>
        public static IEnumerable<MovieElement> GetElements(EntityCollection<Genres> genres)
        {
            var results = new List<MovieElement>();
            foreach (var entity in genres)
                results.Add(GetElement(entity));

            return results;
        }

        /// <summary>
        /// Für das Lesen aller Actors aus Datenbank
        /// </summary>
        public static IEnumerable<MovieElement> GetElements(ObjectSet<Genres> genres)
        {
            var results = new List<MovieElement>();
            foreach (var entity in genres)
                results.Add(GetElement(entity));

            return results;
        }

        /// <summary>
        /// Für das Schreiben der Genres aus Tmdb-Quelle
        /// </summary>
        public static IEnumerable<MovieElement> GetElements(IEnumerable<TmdbMovieCategory> genres)
        {
            var items = new List<MovieElement>();

            foreach (var item in genres)
            {
                items.Add(new MovieElement()
                {
                    Name = item.Name,
                    Type = MovieElementType.Genre
                });
            }

            return items;
        }

        /// <summary>
        /// Für das Schreiben der Genres aus eigener Quelle
        /// </summary>
        public static EntityCollection<Genres> GetEntities(IEnumerable<MovieElement> genres)
        {
            var results = new EntityCollection<Genres>();

            foreach (var item in genres)
                results.Add(GetEntity(item));

            return results;
        }

        public static MovieElement GetElement(Genres genre)
        {
            return new MovieElement()
            {
                Id = genre.Id,
                Name = genre.Name,
                Type = MovieElementType.Genre
            };
        }

        public static Genres GetEntity(MovieElement genre)
        {
            return new Genres()
            {
                Id = genre.Id,
                Name = genre.Name
            };
        }
    }
}
